package simax.integrator.test

import java.text.SimpleDateFormat
import org.junit.Test
import org.junit.Assert
import org.junit.BeforeClass

import simax.integrator.model.*

class RandomMsgGeneratorTests {
	@BeforeClass
	static void init() {
		String.metaClass.testStr = { 
			String s = delegate.trim()
			s.split('\n').collect { (it =~ /^\s+/).replaceFirst('') }.join('\n') 
		}
	}

	@Test
    void testSomething() {
       def generator = new RandomMsgGenerator()
	   def startTime = new SimpleDateFormat('yyyy-MM-dd hh:mm:ss').parse('2013-07-18 00:00:00')
	   def messages  = generator.generate('KFBG', 'LH', startTime, ['E1','E2'], ['L1','L2'])
	   
	   Assert.assertEquals('''
[time:2013-07-18 12:00:01, subject:KFBG.LH.ADSsrv, command:BESTWORK_REQ, header:LH.ADSsrv,LH.WORKmgr,DUMMY, msgbody:EQPID=E2 LOTID=L1]
[time:2013-07-18 12:00:02, subject:KFBG.LH.ADSsrv, command:BESTWORK_REQ, header:LH.ADSsrv,LH.WORKmgr,DUMMY, msgbody:EQPID=E2 LOTID=L2]
[time:2013-07-18 12:00:03, subject:KFBG.LH.ADSsrv, command:BESTWORK_REQ, header:LH.ADSsrv,LH.WORKmgr,DUMMY, msgbody:EQPID=E1 LOTID=L1]
[time:2013-07-18 12:00:04, subject:KFBG.LH.ADSsrv, command:BESTWORK_REQ, header:LH.ADSsrv,LH.WORKmgr,DUMMY, msgbody:EQPID=E1 LOTID=L2]
[time:2013-07-18 12:00:05, subject:KFBG.LH.WORKmgr, command:BESTWORK_REP, header:LH.WORKmgr,LH.ADSsrv,DUMMY, msgbody:EQPID=E2 LOTID=L1]
[time:2013-07-18 12:00:06, subject:KFBG.LH.WORKmgr, command:BESTWORK_REP, header:LH.WORKmgr,LH.ADSsrv,DUMMY, msgbody:EQPID=E2 LOTID=L2]
[time:2013-07-18 12:00:07, subject:KFBG.LH.WORKmgr, command:BESTWORK_REP, header:LH.WORKmgr,LH.ADSsrv,DUMMY, msgbody:EQPID=E1 LOTID=L1]
[time:2013-07-18 12:00:08, subject:KFBG.LH.WORKmgr, command:BESTWORK_REP, header:LH.WORKmgr,LH.ADSsrv,DUMMY, msgbody:EQPID=E1 LOTID=L2]
[time:2013-07-18 12:00:09, subject:KFBG.LH.TOOLmgr, command:TOOL_CONDITION_REQUEST, header:LH.TOOLmgr,LH.WORKmgr,DUMMY, msgbody:EQPID=E2 LOTID=L1]
[time:2013-07-18 12:00:10, subject:KFBG.LH.TOOLmgr, command:TOOL_CONDITION_REQUEST, header:LH.TOOLmgr,LH.WORKmgr,DUMMY, msgbody:EQPID=E2 LOTID=L2]
[time:2013-07-18 12:00:11, subject:KFBG.LH.TOOLmgr, command:TOOL_CONDITION_REQUEST, header:LH.TOOLmgr,LH.WORKmgr,DUMMY, msgbody:EQPID=E1 LOTID=L1]
[time:2013-07-18 12:00:12, subject:KFBG.LH.TOOLmgr, command:TOOL_CONDITION_REQUEST, header:LH.TOOLmgr,LH.WORKmgr,DUMMY, msgbody:EQPID=E1 LOTID=L2]
[time:2013-07-18 12:00:13, subject:KFBG.LH.WORKmgr, command:TOOL_CONDITION_REPLY, header:LH.WORKmgr,LH.TOOLmgr,DUMMY, msgbody:EQPID=E2 LOTID=L1]
[time:2013-07-18 12:00:14, subject:KFBG.LH.WORKmgr, command:TOOL_CONDITION_REPLY, header:LH.WORKmgr,LH.TOOLmgr,DUMMY, msgbody:EQPID=E2 LOTID=L2]
[time:2013-07-18 12:00:15, subject:KFBG.LH.WORKmgr, command:TOOL_CONDITION_REPLY, header:LH.WORKmgr,LH.TOOLmgr,DUMMY, msgbody:EQPID=E1 LOTID=L1]
[time:2013-07-18 12:00:16, subject:KFBG.LH.WORKmgr, command:TOOL_CONDITION_REPLY, header:LH.WORKmgr,LH.TOOLmgr,DUMMY, msgbody:EQPID=E1 LOTID=L2]
[time:2013-07-18 12:00:17, subject:KFBG.LH.EES, command:WORK_ORDER_INFORM, header:LH.EES,LH.WORKmgr,DUMMY, msgbody:EQPID=E2 LOTID=L1]
[time:2013-07-18 12:00:18, subject:KFBG.LH.EES, command:WORK_ORDER_INFORM, header:LH.EES,LH.WORKmgr,DUMMY, msgbody:EQPID=E2 LOTID=L2]
[time:2013-07-18 12:00:19, subject:KFBG.LH.EES, command:WORK_ORDER_INFORM, header:LH.EES,LH.WORKmgr,DUMMY, msgbody:EQPID=E1 LOTID=L1]
[time:2013-07-18 12:00:20, subject:KFBG.LH.EES, command:WORK_ORDER_INFORM, header:LH.EES,LH.WORKmgr,DUMMY, msgbody:EQPID=E1 LOTID=L2]
[time:2013-07-18 12:00:21, subject:KFBG.LH.TC, command:WORK_ORDER_INFORM, header:LH.TC,LH.EES,DUMMY, msgbody:EQPID=E2 LOTID=L1]
[time:2013-07-18 12:00:22, subject:KFBG.LH.TC, command:WORK_ORDER_INFORM, header:LH.TC,LH.EES,DUMMY, msgbody:EQPID=E2 LOTID=L2]
[time:2013-07-18 12:00:23, subject:KFBG.LH.TC, command:WORK_ORDER_INFORM, header:LH.TC,LH.EES,DUMMY, msgbody:EQPID=E1 LOTID=L1]
[time:2013-07-18 12:00:24, subject:KFBG.LH.TC, command:WORK_ORDER_INFORM, header:LH.TC,LH.EES,DUMMY, msgbody:EQPID=E1 LOTID=L2]
		   '''.testStr(), messages.collect { it as String }.join('\n'))	   
    }
}
